package com.hwadee.teachingprocessmanagementsystem.service.base.impl;

import com.hwadee.teachingprocessmanagementsystem.entity.TextbookDistribution;
import com.hwadee.teachingprocessmanagementsystem.dao.TextbookDistributionDao;
import com.hwadee.teachingprocessmanagementsystem.service.base.TextbookDistributionService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import jakarta.annotation.Resource;

/**
 * (TextbookDistribution)表服务实现类
 *
 * @author makejava
 * @since 2024-07-11 14:20:03
 */
@Service("textbookDistributionService")
public class TextbookDistributionServiceImpl implements TextbookDistributionService {
    @Resource
    private TextbookDistributionDao textbookDistributionDao;

    /**
     * 通过ID查询单条数据
     *
     * @param orderId 主键
     * @return 实例对象
     */
    @Override
    public TextbookDistribution queryById(Integer orderId) {
        return this.textbookDistributionDao.queryById(orderId);
    }

    /**
     * 分页查询
     *
     * @param textbookDistribution 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<TextbookDistribution> queryByPage(TextbookDistribution textbookDistribution, PageRequest pageRequest) {
        long total = this.textbookDistributionDao.count(textbookDistribution);
        return new PageImpl<>(this.textbookDistributionDao.queryAllByLimit(textbookDistribution, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param textbookDistribution 实例对象
     * @return 实例对象
     */
    @Override
    public TextbookDistribution insert(TextbookDistribution textbookDistribution) {
        this.textbookDistributionDao.insert(textbookDistribution);
        return textbookDistribution;
    }

    /**
     * 修改数据
     *
     * @param textbookDistribution 实例对象
     * @return 实例对象
     */
    @Override
    public TextbookDistribution update(TextbookDistribution textbookDistribution) {
        this.textbookDistributionDao.update(textbookDistribution);
        return this.queryById(textbookDistribution.getOrderId());
    }

    /**
     * 通过主键删除数据
     *
     * @param orderId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer orderId) {
        return this.textbookDistributionDao.deleteById(orderId) > 0;
    }
}
